<template>
  <loading></loading>
</template>

<script>
import { thirdLogin } from '@/api/user'
import { setToken } from '@/utils/auth'
import Loading from '@/components/loading'

export default {
  name: 'AuthRedirect',
  components: {
    Loading
  },
  created() {
    this.thirdLogin()
  },
  render: function (h) {
    return h() // avoid warning message
  },
  methods: {
    thirdLogin() {
      this.$store.dispatch('setLoading', true);
      let authType = localStorage.getItem('privider')
      let code = this.$route.query.code;
      if (!authType || !code) return
      thirdLogin(authType, { code: code }).then(res => {
        if (res.flag) {
          setToken(res.data.token)
          this.$router.push("/")
        }
      })
    },
  }
}
</script>